package com.cysion.study.ui

import android.content.Intent
import com.cysion.study.ktbox.base.BaseActivity
import com.cysion.study.ktbox.net.BaseResponseRx
import com.cysion.study.ktbox.net.ErrorHandler
import com.cysion.study.ktbox.utils.darkTextTheme
import com.cysion.other.color
import com.cysion.targetfun._subscribe
import com.cysion.study.uibox.bar.TopBar
import com.cysion.study.uibox.dialog.Alert
import com.cysion.study.R
import com.cysion.study.adapter.FriendAdapter
import com.cysion.study.helper.UserCache
import com.cysion.study.net.ApiClient
import com.cysion.study.widget.ShowToast
import kotlinx.android.synthetic.main.activity_friend.*

class FriendActivity : BaseActivity() {

    private lateinit var proAdapter: FriendAdapter
//    private val groupList: MutableList<Staffs> = mutableListOf()
//    private val staffList: MutableList<Staffs> = mutableListOf()

    override fun getLayoutId(): Int = R.layout.activity_friend


    override fun initView() {
        darkTextTheme(color(R.color.main_cl))

        topbar.apply {
            setTitle("选择联系人")
            setOnTopBarClickListener { obj, pos ->
                if (pos == TopBar.Pos.LEFT) {
                    /*var sList: MutableList<Staffs> = mutableListOf()
                    for (i in staffList) {
                        if (i.isCheck) {
                            sList.add(i)
                        }
                    }*/

                    var intent = Intent()
//                    intent.putParcelableArrayListExtra("key", sList as ArrayList<out Parcelable>)
                    setResult(RESULT_OK, intent)
                    finish()
                }
            }
        }
        initRecyclerView()
    }




    //加载数据fileTree
    override fun initData() {
        super.initData()
        //抄送人
        getCopyList()
    }



    private fun getCopyList() {
        Alert.loading(self)
        ApiClient.api.getAll(UserCache.token,"")
            .compose(BaseResponseRx.validateToMain())
            ._subscribe {
                _onNext {
                    Alert.close()
                    if (it.size == 0) {
                        multiView.showEmpty()
                    } else {
                        for (i in it) {
//                            staffList.addAll(i.staffs)
                        }

                        multiView.showContent()
                    }
                }
                _onError {
                    Alert.close()
                    ShowToast(ErrorHandler.handle(it).errorMsg)
                }
            }
    }

    //初始化列表
    private fun initRecyclerView() {


    }


    override fun closeMvp() {
    }

}
